<?php
/***************************************************************************
*                                index.php
 *
 *   Begin date           	: 
 *   Copyright            	: 
 *   Email                	: 
 ***************************************************************************/
define('PHP5_PHP', true);
global $php5DB, $php5DB_en,$php5Config, $php5Template, $php5User, $php5Session, $php5TemplatePath, $php5Msg, $php5Section, $language, $task, $define;
global $msgAlert, $redirect, $php5DB;
include("configs/extension.inc");
include("configs/config".$php5Ext);

$domain = $_SERVER["HTTP_HOST"];
$language = 'en';
$env = 'PC';
/*if($domain=='japan.motul.com') {
    $language = 'jp';
}*/

if(!is_file($php5RootPath . "/includes/php5_common" . $php5Ext)){
    echo "To check the config file.";
    die();
}

require_once($php5RootPath . "/includes/php5_define" . $php5Ext);
require_once($php5RootPath . "/includes/class.inputfilter" . $php5Ext);
require_once($php5RootPath . "/includes/php5_common" . $php5Ext);
require_once($php5RootPath . "/includes/php5_sef" . $php5Ext );
require_once ($php5RootPath.'/includes/smarty.libs/Smarty.class.php');
//require_once($php5RootPath . "/includes/app" . $php5Ext);
//Begin get params
$admin     = php5GetParam($_REQUEST, "t", "");
if(!$php5_sef && $admin=='admin') {
	$admin = 'insite';
}
$task     = php5GetParam($_REQUEST, "task", "");
$type     = php5GetParam($_REQUEST, "o", "main");
$module   = php5GetParam($_REQUEST, "m", "main");
$file     = php5GetParam($_REQUEST, "f", "");
$post    = php5GetParam($_REQUEST, "po", "");
$php5Msg    = php5GetParam($_REQUEST, "msg", "");
$rootPath = $php5RootPath . "/";
if($admin=='insite') {
    $rootPath .= "insite/";
    require_once($php5RootPath . "/languages/".$language."/insite" . $php5Ext); 
} else {
    require_once($php5RootPath . "/languages/".$language."/outsite" . $php5Ext);
}
//End get params
// start init
php5Init( 0 );
if($task == "token") {
	require_once($php5RootPath . "/classes/active_user.class.php" );
	require_once($php5RootPath . "/classes/user.class.php");
	
	$id     = php5GetParam($_REQUEST, "id", "");
	$active_user = new ActiveUser($php5DB);
	$active_user->load($id);
	if($active_user->user_id) {
		$rowUser = new php5User($php5DB);
		$rowUser->load($active_user->user_id);
		$rowUser->status = 1;
		$rowUser->store();
		$active_user->delete();
		
		$php5Session->setVar("user_id", $rowUser->id);
		//$php5Session->setVar("user_name", $rowUser->name);
		$php5Session->setVar("name", $rowUser->name);
		$php5Session->setVar("user_name", $rowUser->username);
		$php5Session->setVar("user_email", $rowUser->email);
		$php5Session->setVar("user_type", $rowUser->type_id);
	}
}
echo "<script>alert('Your account was actived. You can login and use our service');</script>";
echo "<script>window.location.href='".sefBuild($php5WebPath, 'index.php')."';</script>";

?>